package cn.com.dashihui.web.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;

import cn.com.dashihui.web.dao.Strategy;

public class WxStrategyService {

	public List<Strategy> findAllWithCount(){
		return Strategy.me().find("SELECT * FROM t_wx_strategy  ORDER BY orderNo");
	}

	public boolean addStrategy(Strategy article) {
		return article.save();
	}

	public Strategy findById(Integer id) {
		return Strategy.me().findFirst("SELECT * FROM t_wx_strategy WHERE id=?",id);
	}
	/**
	 * 保存分类排序
	 */
	public void sortCategory(Map<String,String> sortMap){
		int batchSize = sortMap.size();
		List<String> sqlList = new ArrayList<String>();
		for(String id : sortMap.keySet()){
			sqlList.add("UPDATE t_wx_strategy SET orderNo="+sortMap.get(id)+" WHERE id="+id);
		}
		Db.batch(sqlList,batchSize);
	}

	public boolean editStrategy(Strategy article) {
		return article.update();
	}
}
